/**
 * Created by seeker910 on 2014/8/20.
 * @description 组件名称命名约定：继承container组件，名称以ViewPart结尾;继承control组件，名称以Part结尾
 * 水平 布局 导航条 
 */
Rsd.define('Rsd.hermit.sections.HNavigationPart', {
    extend: 'Rsd.control.List',
    requires: ['Rsd.form.Label'],
    xtype: 'h-navigation',
     /**
     * @description 标识该组件是否允许编辑
     */
    domEditable:true,
     /**
     * @description true:表示只允许在模板中修改
     */
    editInMaster:true, 
    height:50,
    width:'100%',
    label:false, 
    cls:'x-navigation-h',
    selectedIndex:null,
    itemStyle:{height:'100%',fontSize:'120%'}, 
    itemXtype:'link',//label 通过点击事件跳转，link 通过链接条装
    layout:'hbox',
    dataSource:[],
    schema:{
        for:'',
        title:'菜单', 
        typeof:'object',
        properties:{
            'label':{ 
                title:'logo', 
                 type:'object',
                 properties:{ 
                    xtype:{title:'控件类型',type:'string',default:'image'}, 
                    position: {title:'位置',type:'string',default:'left'},
                    space: {title:'间距',type:'number',default:0},
                    title: {title:'鼠标提示信息',type:'string',default:'Logo'},
                    height: {title:'高度',type:'string',default:'100%'},
                    width: {title:'宽度',type:'string',default:450},
                    src:{title:'图片地址',type:'string',default:'../../resources/svg/rsd_red.svg'}, 
                    label: {title:'文字',type:'object',default:null}
                 }
            },
            'dataSource':{
                type:'array',
                xtype:'list',//list or gird
                itemKeyMember:'id',
                title:'菜单项列表', 
                items: {
                    title:'菜单项',
                    oneOf:['link'],
                    //扩展属性
                    extand:{
                        liStyle:{

                        }
                    }
                },
                 buttons:[
                     { text: '删除', handler: 'btn_item_delete', style: { color: '#fff' } },
                     { text: '修改', handler: 'btn_item_update', style: { color: '#fff' } },
                     { text: '上移', handler: 'btn_item_up', style: { color: '#fff' } },
                     { text: '下移', handler: 'btn_item_down', style: { color: '#fff' } }
                ] 
            }
        }
        
    },
    /**
     * 
     * @param {*} config 
     */
    constructor: function HNavigationPart(config) {
        config = config || {};
        this.apply(config);
    },
    /**
     * 
     */
    onAfterRender:function onAfterRender() {
        this.callParent();
        
        if(this.selectedIndex != null
            && this.selectedIndex > -1
            && this.selectedIndex < this.items.length)
        {
            this.items[this.selectedIndex].addCls('ctrl','x-selected');
        }
    },
    /**
     * 
     */
    loadData:function loadData(data)
    {
        var _data = data||this.dataSource; 
 
         if(Rsd.isEmpty(_data))
         {
            return this;
         }

        if(!Rsd.isArray(_data))
        {
            console.error('Rsd.hermit.sections.HNavigationPart.loadData()方法的data参数必须是数组');
            return this;
        }
        
        var _list = [];
        this.removeAll();
       
        for(var i in _data)
        {
            var item = _data[i];
            if(item.isMenu==false)
            {
                _list.push(Rsd.apply({  
                    text:'',
                    style:{
                        textDecoration:'none',
                        color:'#ffffff',
                        textAlign:'center'
                    },
                    width:150
                },item));
            }
            else
            {
                _list.push(Rsd.apply({  
                    label:false,
                    width:'100%',
                    height:'100%',
                    text:'',
                    cls:'x-menu',
                    style:{
                        textDecoration:'none',
                        color:'#ffffff',
                        textAlign:'center'
                    },
                    flex:10
                },item));
            }
            
        }
        
        this.callParent(_list);
        
        return this;
    }
});
